<?php

namespace Acme\FirmUsersBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class DefaultController extends Controller
{
    /**
     * @Route("/hello/{name}")
     * @Template()
     */
    public function indexAction($name)
    {
        $em = $this->getDoctrine()->getEntityManager();

        $role = new \Acme\FirmUsersBundle\Entity\Role();
        $role->setName('ROLE_FIRM');
        $em->persist($role);
//        $user = new \Acme\FirmUsersBundle\Entity\User();
//        $user->setUsername('alex616');
//        $user->setSalt(md5(time()));
//        $user->setEmail('alexiv616@gmail.com');
//        $encoder = new \Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder('sha512', true,  10);
//        $password = $encoder->encodePassword('admin', $user->getSalt());
//        $user->setPassword($password);
//        $user->getUserRoles()->add($role);
//        $em->persist($user);
        $em->flush();

        return array('name' => $name);
    }
}
